// pages/comment/comment.js
let work={};
const app=getApp()
Page({
    data: {
        display:'none',
        opa:1
    },
    jumpPage:function(e){
        let bid=e.currentTarget.id;
        let uid=wx.getStorageSync('Uid')
        console.log(uid)
        wx.navigateTo({
            url:'/pages/me-homepage/me-homepage?Uid='+uid+'&Bid='+bid
        })
      },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
       this.getRes()
    },
    onShow:function(){
        this.getRes()
    },
    getRes:function(){
        wx.request({
            url: `${app.globalData.url}/message/me-comment?Uid=`+wx.getStorageSync('Uid'),
              success:res=>{
                  console.log(res.data);
                  this.setData({
                      list:res.data
                  })
              }
          })
    },
    addzan:function(e){
        wx.request({
            url:`${app.globalData.url}/message/me-comment`,
            method:'POST',
            data:{
                Cid:e.currentTarget.id,
                Uid:wx.getStorageSync('Uid'),
                Ctime:new Date(),
                img:e.currentTarget.dataset.img=='https://s3.bmp.ovh/imgs/2021/11/8f8308b8016421b4.png'?'https://s3.bmp.ovh/imgs/2021/11/2d7cde86aa7b7457.png':'https://s3.bmp.ovh/imgs/2021/11/8f8308b8016421b4.png'
            },
            success:res=>{
                this.getRes();
            }
        })
    },
    resCom:function(e){
        work=e.currentTarget.dataset.ite
        this.setData({
            display:'block',
            opa:0.1
        })
    },
    formSubmit:function(e){
        console.log(work)
        let time=new Date()
        let year = time.getFullYear()
        let month = time.getMonth() + 1
        let date = time.getDate()
        let hours = time.getHours()
        let minute = time.getMinutes()
        let second = time.getSeconds()
        if (month < 10) { month = '0' + month }
        if (date < 10) { date = '0' + date }
        if (hours < 10) { hours = '0' + hours }
        if (minute < 10) { minute = '0' + minute }
        if (second < 10) { second = '0' + second }
        date=year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + second
        wx.request({
            url:`${app.globalData.url}/addComment/comment`,
            method:'POST',
            data:{
                Wid:work.Cid,
                Uid:wx.getStorageSync('Uid'),
                Ctime:date,
                Czan:0,
                Ctext:e.detail.value.pinglun
            },
            header:{
                'content-type':'application/json'
            },
            success:(res)=>{
                this.setData({
                    display:'none',
                    opa:1
                })
            },
            fail:function(res){
            console.log('失败！')
            }
        })
    },
    changeDetail:function(e){
        let wid=e.currentTarget.id;
        console.log(this.data.Wid);
        wx.navigateTo({
            url:'/pages/com_detail/com_detail?Wid='+wid
        })
    }
})